package com.totobox.apps.activity;

import java.util.Map;

import android.os.Bundle;
import android.sax.TextElementListener;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.totobox.apps.Const;
import com.totobox.apps.R;
import com.totobox.apps.common.MoveActivity;

public class TotoFileDtailActivity extends BasicActivity {
	
	private TextView txt_filename;
	
	//해상도
	private TextView txt_org_resol;
	private TextView txt_high_resol;
	private TextView txt_low_resol;
	
	//파일 사이즈
	private TextView txt_org_size;
	private TextView txt_high_size;
	private TextView txt_low_size;
	
	//재생시간
	private TextView txt_playtime;
	
	private ImageButton btn_play;
	private ImageButton btn_down;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.toto_file_detail);
        
        super.initTitle();
        
        //하단 메뉴 세팅
        super.setFooterMenu(this);
        
        txt_filename = (TextView)findViewById(R.id.txt_filename);
        txt_org_resol = (TextView)findViewById(R.id.txt_org_resol);
        txt_high_resol = (TextView)findViewById(R.id.txt_high_resol);
        txt_low_resol = (TextView)findViewById(R.id.txt_low_resol);
        txt_org_size = (TextView)findViewById(R.id.txt_org_size);
        txt_high_size = (TextView)findViewById(R.id.txt_high_size);
        txt_low_size = (TextView)findViewById(R.id.txt_low_size);
        txt_playtime = (TextView)findViewById(R.id.txt_playtime);
       
        Map<String,String> data = Const.dnQueue.get(0);
        
        //파일 상세 정보
        txt_filename.setText(data.get("vcName"));
        txt_org_resol.setText(data.get("vcOriginResol"));
        txt_high_resol.setText(data.get("vcHighResol"));
        txt_low_resol.setText(data.get("vcLowResol"));
        
        txt_org_size.setText(data.get("biFileSize"));
        txt_high_size.setText(data.get("biHighFileSize"));
        txt_low_size.setText(data.get("biLowFileSize"));
        
        txt_playtime.setText("재생시간 : "+this.getHHMMSS(data.get("vcFilePlayTime")));
        
        btn_play = (ImageButton)findViewById(R.id.btn_play);
        btn_down = (ImageButton)findViewById(R.id.btn_download);
        
        if("VOD".equals(Const.MENU)||"AUD".equals(Const.MENU))
        	btn_play.setOnClickListener(this);
        else
        	btn_play.setEnabled(false);
        
        btn_down.setOnClickListener(this);
        
        
    }

	@Override
	public void onClick(View v) {
		
		if(btn_title_left == v)
			finish();
		else if(btn_play == v){
			if("VOD".equals(Const.MENU)){
				MoveActivity go = new MoveActivity(TotoFileDtailActivity.this , TotoVodPlayerActivity.class);
				go.startActivity();
			}
			else{
				MoveActivity go = new MoveActivity(TotoFileDtailActivity.this , TotoMusicPlayerActivity.class);
				go.startActivity();
			}
		}
		else if(btn_down == v){
			MoveActivity go = new MoveActivity(TotoFileDtailActivity.this , TotoFileConfirmActivity.class);
			go.startActivity();
		}
	}
    
	public String getHHMMSS(String time){
		
		String result = "00:00:00";
		
		if(time == null)
			return result;
		
		try{
			
			int t = Integer.parseInt(time);
			int hou , min , sec;
			
			hou = t/3600;
			int z = t%3600;
			min = z/60;
			sec = z%60;
			
			if(hou == 0) result = "00:";
			else if(hou < 10) result = "0"+hou+":";
			else result = hou+":";
			
			if(min == 0) result += "00:";
			else if(min < 10) result += "0"+min+":";
			else result += min+":";
			
			if(sec == 0) result += "00";
			else if(sec < 10) result += "0"+min;
			else result += min+"";
			
		} catch(Exception e){}
		
		return result;
	}
    
}